package com.iatinspur.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

import java.text.MessageFormat;

@RestController
public class TestController {
    private String name ="黄飞stop" ;

    @Autowired
    private Environment env;

    public String getPort() {
        return env.getProperty("server.port");
    }



    @GetMapping("/getResult")
    public String getResult(){
        System.err.println("在这里");
        /**
         * 读超模拟
         * Read timed out
         */
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return MessageFormat.format("{0}({1})",this.name,getPort());

    }


    @ResponseBody
    @PostMapping("/getResult1")
    public JSONObject getResult1(@RequestBody JSONObject jsonObject){
        return jsonObject;
    }


    @GetMapping("/getResult2")
    public String getResult2(){
        return MessageFormat.format("{0}({1})",this.name,getPort());
    }
}
